<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    用户名：<input type="text" class="b"><input type="checkbox" class="a">记住用户名
</body>
</html>
<script>
    var a=document.querySelector(".a")
    var b=document.querySelector(".b")
    a.onclick=function(){
        if(a.checked==true){
        localStorage.setItem("用户名",b.value)
    }else{
        localStorage.removeItem("用户名")
    }
    }
    if(localStorage.length>0){
        b.value=localStorage.getItem("用户名")
        a.checked=true
    }
</script>